When to change the headers and footers?

Sometimes you want to change the header or footer layout in the course of a document. Some of these changes can be accomplished by using the mark mechanism as may be seen in section [*] and [*]. However, sometimes we want a more drastic change, e.g to change the page numbering from roman to arabic (with \pagenumbering), to change one of the fancyheadings fields or to change to another page style. Sometimes you may be surprised to find the change to occur too early. In general the above mentioned changes take effect immediately, i.e. on the page that is currently being built. If you want the change to take effect at the next page you must make sure that the current page is finished. In most cases this can be done by issuing a \clearpage command before any of the above mentioned changes. If this is not possible you can use the afterpage package with:
\afterpage{\lhead{new value}} or \afterpage{\pagenumbering{roman}}. You cannot use \afterpage to change the \pagestyle as the commands issued by \afterpage are local in a group, and the \pagestyle command makes only local changes. The \pagenumbering and the fancyheadings commands make global changes so they will work, as will the \thispagestyle command.

It should be noted that although the fancyheadings commands like \lhead take effect immediately, this does not mean that any ``variables'' used in these commands get the value they have at the place where these commands are given. E.g. if \cfoot{\thepage} is given the page number that will be inserted in the footer is not the page number of the page where this command is given, but rather the page number of the actual page where the footer is constructed. Of course for the page number this is what you expect, but it is also true for other commands.

So if you have a book where each chapter is written by a different author and you want the name of the author in the lower left-hand corner you can use the following commands:

\newcommand{\TheAuthor}{}
\newcommand{\Author}[1]{\renewcommand{\TheAuthor}{#1}}
\lfoot{\TheAuthor}

and start each chapter with the command \Author{Real Name}. If however, the author name would be changed before a page is completed the wrong author could come in the footer. This would be the case if you gave the above command before the \chapter command rather than after it. Another source of problems is the fact that /'s output routine processes commands ahead, so it may already have processed some commands that produce text that will appear on the next page. See the next section for an example.